<? require("adm_header.php"); 
writeCommonAdminTable(LA_ADMIN_FTPL_NAME,1);?>

<p class="bg"><? echo LA_ADMIN_FTPL_DESCR_1 ?></p>
<p><? echo LA_ADMIN_FTPL_DESCR_2 ?></p>

<form method='post' action='adm_extra.php'>
<input type="submit" name="create_new" value="<? echo LA_ADMIN_FTPL_ADD_NEW ?>" />
</form>
<br /><br /><br /><br />

<?
// Check if global table exist, which it should
$sql="select count(tplid) as num from $template_tbl";
$res_count=q($sql);
$row_c=mysql_fetch_array($res_count);
$num_tpl=$row_c["num"];

// Create global template
if ($num_tpl<1)
	q("INSERT INTO $template_tbl (`tplid`, `name`, `del`) VALUES (1, 'GLOBAL', NULL);");


if (getParam("create_new",""))
	q("insert into $template_tbl (name) values ('')");
if (getParam("delete",""))
	q("delete from $template_tbl where tplid=".getParam("tplid",""));
if (getParam("update",""))
	q("update $template_tbl set name='". getParam("tpl_name","") . "' where tplid=".getParam("tplid",""));
	
$sql="select * from $template_tbl";
$r=q($sql);
while ($row=mysql_fetch_array($r))
{
	echo "<form method='post' action='adm_extra.php' style='margin:0px'>";
	echo "<input type='hidden' name='tplid' value='".$row["tplid"]."'>";
	echo "<input type='text' class='txt' name='tpl_name' value='".$row["name"]."'";
	if ($row["name"]=="GLOBAL")
		echo " disabled='disabled'";
	echo ">";
	echo "&nbsp;<input type='submit' name='update' value='".LA_ADMIN_FTPL_UPDATE."' class='txt'";
	if ($row["name"]=="GLOBAL")
		echo " disabled='disabled'";
	echo ">";
	echo "&nbsp;<input type='submit' name='delete' value='".LA_ADMIN_FTPL_DEL."' class='txt'";
	
	
	$query="select count(q_field) as num from $q_tbl where q_tpl=" . $row["tplid"];
	$res=q($query);
	
	$row_count=mysql_fetch_array($res);
	
	if ($row["name"]=="GLOBAL" || $row_count["num"]>0)
		echo " disabled='disabled'";
	echo ">";
	
	echo "&nbsp;&nbsp; ".LA_ADMIN_FTPL_ISUSED." <b>" . $row_count["num"] . "</b> ".LA_ADMIN_FTPL_TIMES." <a href='adm_fields.php'>".LA_ADMIN_FTPL_QUESTIONS."<u></u></a>.";
	
	echo "</form><br />";
}



writeCommonAdminTable("","");
require("adm_footer.php"); ?>
